package controller.admin;

import java.util.List;

import com.jfinal.aop.Inject;
import com.jfinal.plugin.activerecord.Record;

import controller.admin.base.BaseAdminController;
import model.Menu;
import service.MenuService;

public class AdminMenuController extends BaseAdminController {
	
	@Inject 
	MenuService menuService;
	
    public void list() {
    	List<Record> list = menuService.listAll();
    	renderJson("list", list);
    }
    
    public void info() {
    	Integer id = getParaToInt("id");
        Menu menu = Menu.dao.findById(id);
        set("data", menu);
        set("parentMenuList", menuService.getParentList(menu));
        renderJson();
	}
    
    public void save() {
    	Menu menu = getModel(Menu.class , "x");
    	renderJson(menuService.save(menu));
	}
    
    public void getParentList() {
    	Integer type = getParaToInt("type",2);
    	List<Menu> list = menuService.getParentList(type);
    	renderJson("list", list);
	}
    
    public void delete() {
    	Long id = getParaToLong("id");
    	renderJson(menuService.delete(id));
    }
    
}
